﻿using System;
using IllusionUtility.GetUtility;
using UnityEngine;

namespace Studio
{
	// Token: 0x020004F3 RID: 1267
	public class MapCtr : Singleton<MapCtr>
	{
		// Token: 0x170003AF RID: 943
		// (get) Token: 0x06002027 RID: 8231 RVA: 0x000C8034 File Offset: 0x000C6234
		// (set) Token: 0x06002028 RID: 8232 RVA: 0x000C803C File Offset: 0x000C623C
		public GameObject objMap { get; private set; }

		// Token: 0x06002029 RID: 8233 RVA: 0x000C8048 File Offset: 0x000C6248
		public GameObject LoadMap(int _no)
		{
			this.ReleaseMap();
			Info.LoadCommonInfo loadCommonInfo = null;
			if (!Singleton<Info>.Instance.dicMapLoadInfo.TryGetValue(_no, out loadCommonInfo))
			{
				return null;
			}
			GameObject gameObject = CommonLib.LoadForceAsset<GameObject>(loadCommonInfo.bundlePath, loadCommonInfo.fileName, true, loadCommonInfo.manifest);
			if (gameObject == null)
			{
				GlobalData.Debug_LogError(string.Format("读取失败: {0} : {1} : {2}", loadCommonInfo.manifest, loadCommonInfo.bundlePath, loadCommonInfo.fileName));
				return null;
			}
			gameObject.transform.SetParent(Singleton<Scene>.Instance.commonSpace.transform, false);
			LightMapControl componentInChildren = gameObject.GetComponentInChildren<LightMapControl>();
			if (componentInChildren != null)
			{
				componentInChildren.Apply();
			}
			Transform lightRoot = MapSearch.GetLightRoot(gameObject);
			UnityEngine.Object.Destroy(lightRoot.gameObject);
			Map mapClass = MapSearch.GetMapClass(gameObject);
			mapClass.enabled = false;
			if (_no != 47)
			{
				if (_no == 40 || _no == 42)
				{
					GameObject gameObject2 = gameObject.transform.FindLoop("tv01");
					Renderer component = gameObject2.GetComponent<Renderer>();
					Material material = component.material;
					Texture texture = component.material.GetTexture("_MainTex");
					material.SetTexture("_EmissionMap", texture);
					material.SetColor("_EmissionColor", Color.white);
					component.material = material;
				}
			}
			else
			{
				GameObject gameObject3 = gameObject.transform.FindLoop("o_hs_map10_chair");
				Renderer component2 = gameObject3.GetComponent<Renderer>();
				Material sharedMaterial = component2.sharedMaterial;
				Texture texture2 = component2.material.GetTexture("_MainTex");
				sharedMaterial.SetTexture("_EmissionMap", texture2);
				sharedMaterial.SetColor("_EmissionColor", new Color(0.3f, 0.3f, 0.3f));
				component2.material = sharedMaterial;
			}
			GC.Collect();
			Resources.UnloadUnusedAssets();
			this.objMap = gameObject;
			return this.objMap;
		}

		// Token: 0x0600202A RID: 8234 RVA: 0x000C8220 File Offset: 0x000C6420
		public void ReleaseMap()
		{
			UnityEngine.Object.Destroy(this.objMap);
			this.objMap = null;
			Singleton<Studio>.Instance.cameraLightCtrl.lightMap = null;
		}

		// Token: 0x0600202B RID: 8235 RVA: 0x000C8244 File Offset: 0x000C6444
		protected override void Awake()
		{
			if (!base.CheckInstance())
			{
				return;
			}
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		}
	}
}
